package com.uyaer.wheel.display.widget
{
	import flash.geom.Point;
	
	import starling.display.Image;
	import starling.display.Sprite;

	public class ProgressBar extends Sprite
	{
		private var _backgroundSkin:Image;
		private var _fillSkin:Image;
		private var fullWidth:Number;
		private var _value:Number = 0.0;
		public function ProgressBar()
		{
			super();
		}
		/**
		 *0.0-1.0 
		 * @return 
		 * 
		 */
		public function get value():Number
		{
			return _value;
		}
		/**
		 *0.0-1.0 
		 * @param value
		 * 
		 */
		public function set value(num:Number):void
		{
			num = Math.min(1,Math.max(0,num));
			_value = num;
			_fillSkin.setTexCoords(1,new Point(num,0));
			_fillSkin.setTexCoords(3,new Point(num,1));
			_fillSkin.width = fullWidth * num;
		}
		
		public function set backgroundSkin(skin:Image):void
		{
			if(!_backgroundSkin){
				_backgroundSkin = skin;
				addChildAt(skin,0);
			}else{
				_backgroundSkin.texture = skin.texture;
				_backgroundSkin.width = skin.width;
			}
			this.refresh();
		}
		
		public function set fillSkin(skin:Image):void
		{
			fullWidth = skin.width;
			if(!_fillSkin){
				_fillSkin = skin;
				addChild(skin);
			}else{
				_fillSkin.texture = skin.texture;
			}
			this.refresh();
		}
		/**
		 *设置填充皮肤的偏移 
		 * @param offX
		 * @param offY
		 * 
		 */		
		public function setFillSkinPos(offX:int=0,offY:int=0):void{
			if(_fillSkin){
				_fillSkin.x +=offX;
				_fillSkin.y +=offY;
			}
		}
		
		private function refresh():void{
			if(_fillSkin){
				value = _value;
			}
		}
	}
}